package com.bxw.forum.controller;


import com.bxw.forum.common.AppResult;
import com.bxw.forum.common.ResultCode;
import com.bxw.forum.exception.ApplicationException;
import com.bxw.forum.exception.GlobalExceptionHandler;
import com.bxw.forum.model.Board;
import com.bxw.forum.service.IBoardService;
import com.bxw.forum.utils.MD5Utils;
import com.bxw.forum.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.border.Border;
import javax.xml.crypto.Data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/test")
public class Test {

    @Autowired
    IBoardService boardService;
    int[] arr = new int[]{1,2,3,4,5,6};
    @RequestMapping("/hello")
    public String hello() {
        return "hello SpringBoot...";
    }

    @RequestMapping("/exception")
    public AppResult exception() throws Exception {
        throw new Exception("这是一个异常");
    }

    @RequestMapping("/appException")
    public AppResult appException() {
        throw new ApplicationException("这是一个自定义的异常");
    }

    @RequestMapping("/test1")
    public AppResult<Date> test1() {
        Date date = new Date();
        return AppResult.success(UUIDUtils.UUID_32(),date);
    }

    @RequestMapping("/testmd5")
    public AppResult testmd5() {

        //设置一个固定盐值123
        //进行一次输入和一次校验，分析问题

        String salt = "123";


        String Fmd5 = MD5Utils.md5Salt("123","123");

        System.out.println("输入时MD5"+Fmd5);

        String Smd5 = MD5Utils.md5Salt("123","123");

        System.out.println("校验是MD5"+Smd5);

        if(!Fmd5.equalsIgnoreCase(Smd5)) {

            System.out.println("两次密码不一致");
            return AppResult.fail();
        }

        System.out.println("两次密码一致");
        return AppResult.success();


    }
    @RequestMapping("testBoardIndex")
    public AppResult testBoardIndex() {

        List<Board> list = boardService.selectByNum(1);
        if (list == null) {
            return AppResult.fail("list参数为空");
        }

        return AppResult.success(list);
    }

}
